using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy_Stat : MonoBehaviour
{
    [SerializeField] private EnemyDataSO _enemyDataSO;
    [SerializeField] private EnemyStatGroup _enemyStatGroup;
    private void Start()
    {
        AppayDefaultStatSetup();
    }
    public float GetMaxHealth()
    {
        return _enemyStatGroup.maxHealth.GetValue();
    }
    public float GetAttackRange()
    {
        return _enemyStatGroup.AttackRange.GetValue();
    }
    public float GetAttackSpeed()
    {
        return _enemyStatGroup.AttackSpeed.GetValue();
    }

    public float GetAttackDamage()
    {
        float critChancePercent = _enemyStatGroup.critChance.GetValue() * 100; //暴击率百分比

        bool isCrit = Random.Range(0, 100) < critChancePercent;
        float baseDmage = _enemyStatGroup.baseDamage.GetValue();

        float critDamage = baseDmage * _enemyStatGroup.critPower.GetValue();

        return isCrit ? critDamage : baseDmage;
    }

    [ContextMenu("更新数据")]
    private void AppayDefaultStatSetup()
    {
        if (_enemyDataSO == null)
            return;

        _enemyStatGroup.maxHealth.SetBaseValue(_enemyDataSO.maxHealth);

        _enemyStatGroup.baseDamage.SetBaseValue(_enemyDataSO.baseDamage);

        _enemyStatGroup.AttackRange.SetBaseValue(_enemyDataSO.AttackRange);

        _enemyStatGroup.AttackSpeed.SetBaseValue(_enemyDataSO.AttackSpeed);

        _enemyStatGroup.moveSpeed.SetBaseValue(_enemyDataSO.moveSpeed);

        _enemyStatGroup.critChance.SetBaseValue(_enemyDataSO.critChance);

        _enemyStatGroup.critPower.SetBaseValue(_enemyDataSO.critPower);

        _enemyStatGroup.dropedHp.SetBaseValue(_enemyDataSO.dropedHp);
    }
}
